/*
卷积滤波器头文件
定义卷积核的权重管理和更新机制
支持多种滤波器类型和初始化方法
*/
#ifndef FILTER_H
#define FILTER_H

#include "Macros.h"
#ifdef USE_USER_DEFINED_TENSOR 
    #undef USE_EIGEN_TENSOR
    #include "Tensor.h"
#endif
#ifdef USE_EIGEN_TENSOR
    #undef USE_USER_DEFINED_TENSOR
    #include <Eigen/Core>
    #include <Eigen/Dense>
#endif
#include <vector>
#include <memory>

#ifdef USE_EIGEN_TENSOR
// Enable Eigen parallelization
#define EIGEN_USE_THREADS
#endif

using namespace std;
#ifdef USE_EIGEN_TENSOR
using namespace Eigen;
#endif
#ifdef USE_USER_DEFINED_TENSOR
using namespace UserDefinedTensor;
#endif

class Filter {
public:
    Filter(int filterIndex, int inputChannels, int filterWidth, int filterHeight);
    ~Filter();
    const int getFilterIndex() const;
    const int getInputChannels() const;
    const int getFilterWidth() const;
    const int getFilterHeight() const;
    const Tensor<double, 3> getWeights() const;
    const Tensor<double, 1> getBiases() const;
    void setWeights(const Tensor<double, 3>& weights);
    void setBiases(const Tensor<double, 1>& biases);
    const vector<double> getOutputs() const;
    void forward(const Tensor<double, 3>& inputFeatureMap);
    void backward(const Tensor<double, 3>& target);
    void print() const;

private:
    int filterIndex;
    int inputChannels;
    int filterWidth;
    int filterHeight;
    Tensor<double, 3> weights;
    Tensor<double, 1> biases;
    Tensor<double, 3> outputFeatureMap;
};

#endif // FILTER_H